package cn.wolfcode.p2p.base.domain;

import cn.wolfcode.base.BaseDomain;
import cn.wolfcode.p2p.base.util.BitStateUtil;
import cn.wolfcode.p2p.base.util.MaskUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

;

/**
 * @author
 * @since 2018-11-24 11:48:38
 */
@Getter
@Setter
@Accessors(chain = true)
public class UserInfo extends BaseDomain {
    /**
     * 乐观锁
     */
    private Integer version = 0;

    /**
     * 位状态码
     */
    private Long bitState = 0L;

    /**
     * 身份证号码
     */
    private String idNumber;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 手机号码
     */
    private String phoneNumber;

    /**
     * 电子邮箱
     */
    private String email;

    /**
     * 实名认证信息ID
     */
    private Long realAuthId;

    /**
     * 视频认证信息ID
     */
    private Long videoAuthId;

    /**
     * 婚姻情况
     */
    private SystemDictionaryItem marriage;

    /**
     * 子女数量情况
     */
    private SystemDictionaryItem kidCount;
    /**
     * 收入情况
     */
    private SystemDictionaryItem incomeGrade;

    /**
     * 教育背景情况
     */
    private SystemDictionaryItem educationBackground;

    /**
     * 住房条件情况
     */
    private SystemDictionaryItem houseCondition;

    /**
     * 判断是否已经实名认证
     *
     * @return
     */
    public Boolean getHasRealAuth() {
        return BitStateUtil.hasState(this.bitState, BitStateUtil.OP_REAL_AUTH);
    }

    /**
     * 判断是否有基本资料
     *
     * @return
     */
    public boolean getHasBasicInfo() {
        return BitStateUtil.hasState(this.bitState, BitStateUtil.OP_BASIC_INFO);
    }

    /**
     * 判断是否有视频认证
     *
     * @return
     */
    public boolean getHasVideoAuth() {
        return BitStateUtil.hasState(this.bitState, BitStateUtil.OP_VIDEO_AUTH);
    }

    /**
     * 判断三种认证是否都完成
     *
     * @return
     */
    public boolean getBorrowable() {
        return this.getHasRealAuth() && this.getHasBasicInfo() && this.getHasVideoAuth();
    }


    /**
     * 判断是否在申请借款流程中
     *
     * @return
     */
    public boolean getHasBorrowApply() {
        return BitStateUtil.hasState(this.bitState, BitStateUtil.OP_HAS_BIDREQUEST_PROCESS);
    }


    /**
     * 跟新状态
     * long state = BitStateUtil.addState(current.getBitState(), BitStateUtil.OP_BASIC_INFO);
     */
    public Long getNewState(Long newSate) {
        return BitStateUtil.addState(this.getBitState(), newSate);
    }

    /**
     * 提那就新的状态
     *
     * @param newSate
     * @return
     */
    public Long addNewState(int newSate) {
        return BitStateUtil.addState(this.getBitState(), newSate);
    }

    // 获取脱敏后的真实名字
    public String getAnonymousRealName() {
        return MaskUtil.getAnonymousRealName(realName);
    }

    // 获取脱敏后的号码
    public String getAnonymousIdNumber() {
        return MaskUtil.getAnonymousIdNumber(idNumber);
    }

    /**
     * 借款申请流程
     *
     * @return
     */
    public boolean getHasRequestInProcess() {
        return BitStateUtil.hasState(this.bitState, BitStateUtil.OP_HAS_BIDREQUEST_PROCESS);
    }
}